import {webviewRunCode} from '../utils'
import propapp from './propapp'
import elementapp from './elementapp'
import comapp from './comapp'
import startapp from './startapp'

function inspectElement(webview, treeNode) {
  webviewRunCode(webview,
    `
   var a = document.querySelector('[sid="${treeNode.id}"]');
   if (a) {
        console.log(a)
        console.dir(a) 
        console.log('-------------------') 
        let data = a.getBoundingClientRect()
   
         function respond(event) {
          event.source.postMessage(data, '*');
        }
  
        window.addEventListener("message", respond, false);
   }
    `).then(res => {
    // webview.inspectElement(parseInt(res.x), parseInt(res.y))
  })
}

document.addEventListener('com:selected', function (e) {
  let {treeNode} = e.detail
  let webview = document.getElementById('testWebview')
  console.log('com:selected', treeNode, webview)
  inspectElement(webview, treeNode)
  propapp(treeNode)
})

elementapp()
comapp()
startapp()
